package com.sc.pattern.pc;

import java.util.concurrent.atomic.AtomicInteger;

/**
 * Created  on 2018/1/13.
 *
 * @author sc
 */
public class Producer extends Thread{
    private final MessageQueue queue;
    private final static AtomicInteger counter = new AtomicInteger(0);
    public Producer(MessageQueue queue) {
        super("producer");
        this.queue = queue;
    }

    @Override
    public void run() {
        while (true){
            try {
                queue.put(new Message("message"+counter.getAndIncrement()));
                Thread.sleep(1000);
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
        }
    }
}
